﻿using System.Net;

namespace Transformable_Engine_v2.Engine.Network.Interfaces
{
    public abstract class BaseNetworkClient
    {
        public delegate void OnStartListenEvent();

        public event OnStartListenEvent OnStartListen;

        public delegate void OnReceiveEvent(IPEndPoint senderInfo,
                                       byte[] messageReceived);

        public event OnReceiveEvent OnReceive;

        public delegate void OnSendEvent(string hostName, string port,
                                         byte[] messageSent);

        public event OnSendEvent OnSend;

        public enum ClientType
         {
             Sync,
             Async
         }

        protected bool _isRunning;

        protected BaseNetworkClient()
        {
            _isRunning = true;
        }

        

        protected void RaiseOnSendEvent(string recipientInfo, string recipientPort,
                                         byte[] messageSent)
        {
            if(OnSend != null)
                OnSend(recipientInfo, recipientPort, messageSent);
        }

        protected void RaiseOnReceiveEvent(IPEndPoint senderInfo,
                                        byte[] messageReceived)
        {
            if(OnReceive != null)
                OnReceive(senderInfo, messageReceived);
        }

        protected void RaiseOnStartListenEvent()
        {
            if(OnStartListen != null)
                OnStartListen();
        }

        public void Close()
        {
            _isRunning = false;
        }
    }
}